package com.example.demo.controller.warehouse;



import com.example.demo.model.ResponseMessage;
import com.example.demo.model.warehouse.Product;
import com.example.demo.service.warehouse.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService service;


    @RequestMapping("save")
    public ResponseMessage save(Product product){
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = service.save(product);
        responseMessage.setFlag(flag);

        return  responseMessage;
    }
    //    查询全部
    @RequestMapping("selectAll")
    public List<Product> selectAll(){return service.selectAll();}
    //    添加数据
    @RequestMapping("addProduct")
    public Integer addProduct(Product product){return service.addProduct(product);}
    //删除数据
    @RequestMapping("deleteById")
    public Boolean deleteById(Integer product_id){return service.deleteById(product_id)==1;}
    @RequestMapping("updateById")
    public Integer updateById(Product product){return service.updateById(product);}

    @RequestMapping("updateStatusById")
    Integer updateStatusById(Integer product_id){return service.updateStatusById(product_id);}

    @RequestMapping("findProduct")
    @ResponseBody
    public List<Product> findProduct(String product_name,Integer id,Integer product_model,Integer product_unit){ return service.findProduct( product_name,id,product_model,product_unit); }

    @RequestMapping("All")
    @ResponseBody
    public List<Product> All(){return service.All();}
}
